<template>
  <a-card :bordered="false">
    <a-spin :spinning="spinning != 0">
      <!-- 查询区域-->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.system.portalset.entity.portletName')">
                <a-input placeholder="" v-model="queryParam.portletName$lk"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
                <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
        <a-button @click="handleBatchDel" type="default"  icon="delete" v-test>{{ $t('m.common.button.delete') }}</a-button>
      </div>

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          :rowKey="rowKey"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="pagination"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange"
          :customRow="clickThenCheck"
        >
          <template slot="serialNum" slot-scope="text,record,index">
            {{(pagination.current-1) * pagination.pageSize + parseInt(index) + 1}}
          </template>
          <template slot="action" slot-scope="text, record">
            <a @click="handleEdit(record)">
              {{ $t('m.common.button.update') }}
            </a>
            &nbsp;<a-divider type="vertical"/>
            <a @click="design(record)">
              {{ $t('m.common.button.design') }}
            </a>
            <a-divider type="vertical"/>
            <a-dropdown>
              <a class="ant-dropdown-link">{{$t('m.common.button.more')}}
                <ych-icon type="down"/>
              </a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a @click="auth(record)">{{$t('m.system.portalset.other.authorize')}}</a>
                </a-menu-item>
                <a-menu-item>
                  <a @click="handleDel(record)" v-test>{{ $t('m.common.button.delete') }}</a>
                </a-menu-item>
              </a-menu>
            </a-dropdown>
          </template>

        </a-table>
      </div>
    </a-spin>

    <!-- 表单区域 -->
    <PortletConfigFormDialog ref="form" @refreshParent="modalFormOk"/>

    <!-- 门户配置设计弹窗 -->
    <AsyncComponent
      v-if="showEditIndexModal"
      :ref="portalDesignRefName"
      :path="portalDesignPath"
      :widgetForm = "widgetForm"
      :portLet = "portLet"
      @closeModal = "handeleCloseDesignMd"
      @updatePortLetList="updatePortLetList"
    />
    <PortletRoleAuthModal ref="roleAuth"></PortletRoleAuthModal>
  </a-card>
</template>

<script>

  import {ViewMixin} from '@/mixins/ViewMixin'
  import PortletConfigFormDialog from './modules/PortletConfigFormDialog'
  import { PortletSettingMixin } from '@/framework/FormMaking/mixins/PortletSettingMixin.js'
  import { getAction,deleteAction } from '@/api/manage'
  import PortletRoleAuthModal from './modules/PortletRoleAuthModal'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "PortalSettingPage",
    mixins: [ViewMixin,PortletSettingMixin],
    components: {
      PortletConfigFormDialog,PortletRoleAuthModal
    },
    data() {
      return {
        formCode: 'portlet_sysPortletConfigForm',
        tableName: 'sys_portlet_config',
        dictConfig: {},
        optionConfig: {},
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.system.portalset.entity.portletName'),
            dataIndex: 'portletName',
            align: 'center',
          },
          {
            title: this.$t('m.system.portalset.entity.portletCode'),
            dataIndex: 'portletCode',
            align: 'center',
          },
          {
            title: this.$t('m.system.portalset.entity.isDefault'),
            dataIndex: 'isDefault',
            align: 'center',
            customRender: (text, row, index) => {
                if(text=="1"){
                  return "是"
                }else{
                  return "否"
                }

            },
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            width: 220,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/portlet/list",
          delete: YchConstant.PREFIX_SYSTEM + "/portlet/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/portlet/deleteBatch",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/portlet/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/portlet/importExcel",
          getPortLetByCode:YchConstant.PREFIX_SYSTEM + "/portlet/getPortLetByCode"
        },
      }
    },
    methods: {
      design(record){
        this.loading = true
        let param = {};
        param.portletCode = record.portletCode;
        getAction(this.url.getPortLetByCode, param).then(res => {
          if (res.success) {
            this.openPortalDesign(res.result)
          } else {
            this.messageUtil.warning(res.message)
          }
          this.loading = false
        })
      },
      auth(record){
        this.$refs.roleAuth.show(record.portletCode);
      }
    },
    watch: {
      pkFlg() {
        this.watchPk()
      }
    }
  }
</script>
<style lang="less" scoped>

</style>
